//
//  JBParallaxTableViewController.m
//  myDemo2
//
//  Created by wuxueying on 14-4-14.
//
//

#import "JBParallaxTableViewController.h"
#import "UIImageView+WebCache.h"
#import "JBParallaxCell.h"

@interface JBParallaxTableViewController ()<UIScrollViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong) NSArray *tableItems;
@end
@implementation JBParallaxTableViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.tableItems = @[@"http://d.hiphotos.baidu.com/image/w%3D2048/sign=d526d7b8bb014a90813e41bd9d4f3812/562c11dfa9ec8a13a8163feaf503918fa0ecc0a8.jpg",
                        @"http://c.hiphotos.baidu.com/image/w%3D2048/sign=0fb67cc69b25bc312b5d06986ae78cb1/6609c93d70cf3bc7bd7e64e4d300baa1cd112abf.jpg",
                        @"http://e.hiphotos.baidu.com/image/w%3D2048/sign=17735c757af0f736d8fe4b013e6db319/1e30e924b899a901f01f313c1f950a7b0208f596.jpg",
                        @"http://img0.bdstatic.com/img/image/shouye/leimu/mingxing.jpg",
                        @"http://img.baidu.com/img/image/3bf33a87e950352a5947ae485143fbf2b2.jpg",
                        @"http://img1.bdstatic.com/img/image/8662934349b033b5bb5c55e5d9834d3d539b700bcce.jpg",
                        @"http://imgstatic.baidu.com/img/image/7af40ad162d9f2d3cdc19be8abec8a136227cce1.jpg",
                        @"http://imgstatic.baidu.com/img/image/weimeiyijing0207.jpg",
                        @"http://e.hiphotos.baidu.com/image/w%3D400/sign=2e56c8010ed79123e0e095749d355917/ae51f3deb48f8c5470385d2638292df5e1fe7fd4.jpg",
                        @"http://c.hiphotos.baidu.com/image/w%3D400/sign=e37cc47c6509c93d07f20ff7af3cf8bb/7a899e510fb30f2468cc6271ca95d143ad4b0369.jpg",
                        @"http://b.hiphotos.baidu.com/image/w%3D400/sign=ac0b8e2b92ef76c6d0d2fa2bad17fdf6/a71ea8d3fd1f4134dedc5974271f95cad0c85ed4.jpg",
                        @"http://imgstatic.baidu.com/img/image/huacaozhiwu0207.jpg",
                        @"http://d.hiphotos.baidu.com/image/w%3D400/sign=7d27c75af4246b607b0eb374dbf81a35/5882b2b7d0a20cf4f28367d674094b36acaf99ac.jpg",
                        @"http://f.hiphotos.baidu.com/image/w%3D400/sign=657110132ff5e0feee1888016c6134e5/c83d70cf3bc79f3d6db2fb3ab8a1cd11728b296c.jpg",
                        @"http://g.hiphotos.baidu.com/image/w%3D400/sign=4be7f3c141166d223877149476230945/e850352ac65c10384d5fbac8b0119313b07e8992.jpg",
                        @"http://imgstatic.baidu.com/img/image/meinvbizhi0207.jpg",
                        @"http://h.hiphotos.baidu.com/image/w%3D400/sign=880260efb68f8c54e3d3c42f0a292dee/d0c8a786c9177f3e405a5a0c72cf3bc79f3d5640.jpg",
                        @"http://a.hiphotos.baidu.com/image/w%3D400/sign=55af4af479899e51788e3b1472a7d990/f9198618367adab42ab8824a89d4b31c8701e44b.jpg",
                        @"http://imgstatic.baidu.com/img/image/a50f4bfbfbedab64947d23a7f536afc379311e4d.jpg",
                        @"http://img2.bdstatic.com/img/image/5086f061d950a7b0208c22b6db060d9f2d3562cc885.jpg",
                        @"http://imgstatic.baidu.com/img/image/6a.jpg"];
}


- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [self scrollViewDidScroll:nil];
}

- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.tableItems.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"parallaxCell";
    JBParallaxCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    cell.titleLabel.text = [NSString stringWithFormat:NSLocalizedString(@"Cell %d",), indexPath.row];
    cell.subtitleLabel.text = [NSString stringWithFormat:NSLocalizedString(@"This is a parallex cell %d",),indexPath.row];
    [cell.parallaxImage setImageWithURL:[NSURL URLWithString:self.tableItems[indexPath.row]]];
    return cell;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    NSArray *visibleCells = [self.tableView visibleCells];
    for (JBParallaxCell *cell in visibleCells) {
        [cell cellOnTableView:self.tableView didScrollOnView:self.view];
    }
}


@end
